{include file="public/top_and_left"}

<!--编辑器-->
<link href="{$admin['vendor']}/umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="{$admin['vendor']}/umeditor/third-party/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8" src="{$admin['vendor']}/umeditor/umeditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="{$admin['vendor']}/umeditor/umeditor.min.js"></script>
<script type="text/javascript" src="{$admin['vendor']}/umeditor/lang/zh-cn/zh-cn.js"></script>

<article class="page-container">
    <div class="form form-horizontal" id="form-article-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>文章标题：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="title" name="">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>分类栏目：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="" class="select" id="catid">
                    <option value="0">请选择栏目</option>
                    {volist name="group" id='v'}
                    <option value="{$v['id']}">{$v['title']}</option>
                    {/volist}
                </select>
				</span></div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">缩略图：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="uploader-thum-container">
                    <img src="1.png" width="100px" height="100px" id="img_url"/>
                    <input type="file" id="upload_img">
                </div>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">文章内容：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <script id="myEditor" type="text/plain" style="width:100%;height:450px;"></script>
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <button onClick="article_save_submit();" class="btn btn-primary radius" type="submit">点击添加</button>
                <button onClick="removeIframe();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
                <input id="thumb" type="">
            </div>
        </div>
    </div>
</article>

<script type="text/javascript" src="{$admin['js']}/uediter.js"></script>
{include file="public/foot"}

<script>
    //上传图片
    $("#upload_img").change(function () {
        var formData = new FormData();
        formData.append("upload_img", $("#upload_img")[0].files[0]);
        $.ajax({
            type: 'post',
            url: "{:url('ajax/upload')}",
            data: formData,
            processData: false,
            contentType: false,
            success: function (data) {
                if (data.status == 200) {
                    $("#img_url").attr('src', data.info);
                    $("#thumb").val(data.info);
                } else {
                    layer.msg(data.mes);
                }
            }
        });
    })


    //添加文章
    function article_save_submit() {
        var title = $("#title").val().replace(/\s*/g, "");
        var catid = $("#catid").val();
        var content = um.getContent();
        var thumb = $("#thumb").val().replace(/\s*/g, "");
        if(!title){
            layer.msg("请输入标题");
            return false;
        }
        if(catid==0){
            layer.msg("请选择栏目");
            return false;
        }
        add(title, catid, content, thumb);
    }
    function add(title, catid, content, thumb) {
        $.post("{:url('news/add')}", {title:title,catid:catid,content:content,thumb:thumb}, function (data) {
            layer.msg(data.mes);
            if (data.status == 200) {
                window.location.href = "{:url('news/index')}";
            }
            ;
        })
    }
</script>
